package src

import (
	"fmt"
	"net/http"
	"regexp"
	//"strconv"
//	"github.com/PuerkitoBio/goquery"
//	"utils"
	//"time"
//	"appengine"
	//"appengine/taskqueue"
	//"appengine/memcache"
//	"appengine/urlfetch"
)

func init() {
	http.HandleFunc("/demo", demoHandler)
}


func demoHandler(w http.ResponseWriter, r *http.Request) {
//	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
//	
//	fmt.Fprintln(w, "hello hoasgganbn")
//	fmt.Println("hoanbn")
//	
//	url := "http://callderheart.wordpress.com/2014/03/14/kim-ha-eum-talesweaver-only-u-concert"
//	
//	var doc *goquery.Document
//  	var e error
//
//	c := appengine.NewContext(r)
//	client := urlfetch.Client(c)
//	
//	resp, err := client.Get(url)
//	
//	if  err != nil {
//		panic(err.Error())
//	}
//
//	if doc, e = goquery.NewDocumentFromResponse(resp); e != nil {
//		panic(e.Error())
//	}
//	
//	doc.Find(".entry-title").Each(func(i int, s *goquery.Selection) {
//		fmt.Fprintln(w, s.Text())
//	})


//	str := "=== Jetpack by WordPress.com === Contributors: automattic, alternatekev, andy, apeatling, azaozz, barry, beaulebens, blobaugh, cfinke, chellycat, ";
//	re := regexp.MustCompile(`[=]{3}([^=]+)+[=]{3}`)
//	rs := re.FindString(str)
//	fmt.Fprintln(w, rs)
//	fmt.Fprintln(w, utils.GetStringUpperLongest(str))
	
	
	
	
	
	//fmt.Fprintln(w, re.FindAllString(str, -1))
	
//	rs := re.FindStringSubmatchIndex(str)
//	fmt.Fprintln(w, rs)
//	fmt.Fprintln(w, re.FindAllString(str, 12))
	
//	for i := 0 ; i < len(rs); i++ {
//		fmt.Fprintln(w, re.FindAllString(str, rs[i]);
//	}
	
	
	fmt.Fprintln(w, r.Host)
	str := "http://www.google.com/asdfasdfsd?asdfasdf=dasfasdsdf"
	re := regexp.MustCompile(`^((http://)|(https://)){1}[a-zA-Z0-9-]+([.]{1}[a-zA-Z0-9-]+)+([/]+[^/]*)*`)
	
	if (re.MatchString(str)) {
		fmt.Fprintln(w, "Is url valid")
	} else {
		fmt.Fprintln(w, "Not valid Url")
	}
		
}
